using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataAccessLayer
{
    public class DAO_Test_Section
    {
        public static bool Insert(Object tmp)
        {
            TEST_SECTION obj = (TEST_SECTION)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@TEST_ID", obj.TEST_ID));
            _list.Add(new SqlParameter("@TEST_SECTION_DESC", obj.TEST_SECTION_DESC));
            _list.Add(new SqlParameter("@TEST_SECTION_ID", obj.TEST_SECTION_ID));

            int n = clsDataAccessHelper.ExecNonQuery("sp_test_section_insert", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static bool Update(Object tmp)
        {
            TEST_SECTION obj = (TEST_SECTION)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@TEST_ID", obj.TEST_ID));
            _list.Add(new SqlParameter("@TEST_SECTION_DESC", obj.TEST_SECTION_DESC));
            _list.Add(new SqlParameter("@TEST_SECTION_ID", obj.TEST_SECTION_ID));

            int n = clsDataAccessHelper.ExecNonQuery("sp_test_section_update", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static bool Delete(Object tmp)
        {
            TEST_SECTION obj = (TEST_SECTION)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@TEST_ID", obj.TEST_ID));
            _list.Add(new SqlParameter("@TEST_SECTION_DESC", obj.TEST_SECTION_DESC));
            _list.Add(new SqlParameter("@TEST_SECTION_ID", obj.TEST_SECTION_ID));

            int n = clsDataAccessHelper.ExecNonQuery("sp_test_section_delete", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static List<TEST_SECTION> LoadAll()
        {
            List<TEST_SECTION> _list = new List<TEST_SECTION>();
            //call stored getlist here
            return _list;
        }

        public static DataTable Load(Object tmp)
        {
            TEST obj = (TEST)tmp;
            List<SqlParameter> _list = new List<SqlParameter>();

            if (!string.IsNullOrWhiteSpace(obj.TEST_ID))
            {
                _list.Add(new SqlParameter("@TEST_ID", obj.TEST_ID));
            }
            else
            {
                _list.Add(new SqlParameter("@TEST_ID", DBNull.Value));
            }
            if (!string.IsNullOrWhiteSpace(obj.COURSE_ID))
            {
                _list.Add(new SqlParameter("@COURSE_ID", obj.COURSE_ID));
            }
            else
            {
                _list.Add(new SqlParameter("@COURSE_ID", DBNull.Value));
            }

            if (!string.IsNullOrWhiteSpace(obj.USER_ID))
            {
                _list.Add(new SqlParameter("@USER_ID", obj.USER_ID));
            }
            else
            {
                _list.Add(new SqlParameter("@USER_ID", DBNull.Value));
            }

            return clsDataAccessHelper.ExecuteQuery("sp_test_section_load", _list);
        }

        public static DataTable Get(Object tmp)
        {
            TEST obj = (TEST)tmp;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@TEST_ID", obj.TEST_ID));

            return clsDataAccessHelper.ExecuteQuery("sp_test_section_get", _list);
        }

        public static DataTable GetQuestions(decimal testSection_ID)
        {
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@TEST_SECTION_ID", testSection_ID));

            return clsDataAccessHelper.ExecuteQuery("sp_test_section_get_questions", _list);
        }

        public static DataTable GetTestSection(decimal testSection_ID)
        {
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@TEST_SECTION_ID", testSection_ID));

            return clsDataAccessHelper.ExecuteQuery("sp_test_section_get_info", _list);
        }

        public static DataTable GetTestSectionQuestions(decimal testSection_ID)
        {
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@TEST_SECTION_ID", testSection_ID));

            return clsDataAccessHelper.ExecuteQuery("sp_test_section_questions", _list);
        }

        public static DataTable GetTestSectionQuestionIDs(string questionIDs)
        {
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@QUESTIONIDS", questionIDs));

            return clsDataAccessHelper.ExecuteQuery("sp_test_section_question_ids", _list);
        }
    }
}
